<template lang="html">
    <el-row :gutter="24">
        <el-col :span="23">
            <el-card class="box-card configure">
                <div slot="header" class="clearfix">
                    <span style="line-height: 36px;">小说搜索 <i class="el-icon-search"></i></span>
                    <el-col :span="4" style="float: right;">
                        <el-input placeholder="小说" v-model="search.title" v-on:change="search($search)">
                            <el-button slot="append" icon="search" v-on:click="search()"></el-button>
                        </el-input>
                    </el-col>
                </div>
                <el-table v-loading.body="loading" :data="sreachResp" class="adminsearch-table">
                    <el-table-column prop="title" label="小说"></el-table-column>
                    <el-table-column prop="search" label="搜索文本"></el-table-column>
                    <el-table-column prop="from" label="原网址"></el-table-column>
                    <el-table-column inline-template prop="from" fixed="right" width="100" align="center" label="操作">
                    <span><el-button v-on:click="addNovelTask(row.from)"  type="text">添加</el-button></span>
                    </el-table-column>
                </el-table>
            </el-card>
        </el-col>
    </el-row>
</template>

<script type="text/babel">
export default {
    data: () => {
        return {
            search: {
                title: ""
            },
            sreachResp: [],
            loading:false
        }
    },
    methods: {
        search: function() {
            var _this = this
            if (_this.search.title == "") {
                return
            }
            _this.loading = true
            _this.$http.post("http://novel.nightc.com/v1/search", {
                title: _this.search.title
            }).then((response) => {
                var body = response.body
                if (body.code != undefined && body.code == 0) {
                    _this.sreachResp = []
                    for (var i in body.data) {
                        _this.sreachResp.push({
                            title: body.data[i].Name,
                            search: body.data[i].SearchName,
                            from: body.data[i].From
                        })
                    }
                }
                _this.loading = false
            })
        },
        addNovelTask: function(url) {
            var _this = this
            _this.$http.post("http://novel.nightc.com/v1/novel/task", {
                url: url
            }).then((response) => {
                var body = response.body
                if (body.code != undefined && body.code == 0) {
                    _this.$message({
                        message: '添加成功',
                        type: 'success'
                    });
                } else {
                    _this.$message({
                        message: '添加失败',
                        type: 'error'
                    });
                    console.log(body)
                }
            })
        }
    }
}
</script>

<style lang="css" rel="stylesheet/css">
.configure {
    width: 100%;
    min-height: 600px;
}
h2 {
    line-height: 36px;
    color: #475669;
}
</style>
